package listbyorder.access101_200.test165;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/13 14:25
 */
public class Solution1 {

    public int compareVersion(String version1, String version2) {
        String[] split1 = version1.split("\\.");
        String[] split2 = version2.split("\\.");
        int i = 0, j = 0;
        while (i < split1.length || j < split2.length) {
            String num1 = i < split1.length ? split1[i] : "0";
            String num2 = j < split2.length ? split2[j] : "0";
            int res = compare(num1, num2);
            if (res == 0) {
                i++;
                j++;
            } else {
                return res;
            }
        }
        return 0;
    }

    private int compare(String num1, String num2) {
        int n1 = Integer.parseInt(num1);
        int n2 = Integer.parseInt(num2);
        if (n1 > n2) {
            return 1;
        } else if (n1 < n2) {
            return -1;
        } else {
            return 0;
        }
    }
}
